/**
 * @file STL_ModLog.h
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief 
 * @version 0.1
 * @date 2021-07-26
 * 
 * @copyright Copyright (c) 2021
 * 
 */

#ifndef _STL_LOG_H_
#define _STL_LOG_H_

#include <string>
#include <functional>
#include "STLOG.h"
#include "STL_Timestamp.h"
#include <stdarg.h> // va_start va_end

namespace STL
{
    class STL_ModLog
    {
    public:
        typedef enum Level_e
        {
            STL_ModLog_Trace,
            STL_ModLog_Debug,
            STL_ModLog_Info,
            STL_ModLog_Warn,
            STL_ModLog_Error,
            STL_ModLog_Fatal,
            STL_ModLog_MAX = STL_ModLog_Fatal
        } Level;

        typedef std::function<void(std::string /* tag*/, STL_ModLog::Level /* level*/, std::string /* log*/)> LogCallback;

    public:
        STL_ModLog();
        STL_ModLog(std::string tag);
        ~STL_ModLog();

    public:
        std::string m_tag;
        void setTag(std::string tag)
        {
            m_tag = tag;
        };

    public:
        bool m_color;
        void setColor(bool color)
        {
            m_color = color;
        }

    public:
        std::string m_timestampFormat;
        void setTimestampFormat(std::string fmt)
        {
            m_timestampFormat = fmt;
        }

    public:
        STL::STL_ModLog::Level m_level;
        void setLogLevel(STL::STL_ModLog::Level level = STL::STL_ModLog::Level::STL_ModLog_Debug)
        {
            m_level = level;
        };

    public:
        STL::STL_ModLog::LogCallback m_logCallback;
        void setLogCallback(STL::STL_ModLog::LogCallback callback)
        {
            m_logCallback = callback;
        };

    public:
        void stl_modlog(STL::STL_ModLog::Level level, const char *format, ...);
    };
}

// 痕迹
#define modlog_trace(format, args...) (stl_modlog(STL::STL_ModLog::STL_ModLog_Trace, format, __FILE__, __LINE__, __FUNCTION__, ##args))

// 调试
#define modlog_debug(format, args...) (stl_modlog(STL::STL_ModLog::STL_ModLog_Debug, format, __FILE__, __LINE__, __FUNCTION__, ##args))

// 信息
#define modlog_info(format, args...) (stl_modlog(STL::STL_ModLog::STL_ModLog_Info, format, __FILE__, __LINE__, __FUNCTION__, ##args))

// 警告
#define modlog_warn(format, args...) (stl_modlog(STL::STL_ModLog::STL_ModLog_Warn, format, __FILE__, __LINE__, __FUNCTION__, ##args))

// 错误
#define modlog_error(format, args...) (stl_modlog(STL::STL_ModLog::STL_ModLog_Error, format, __FILE__, __LINE__, __FUNCTION__, ##args))

// 致命
#define modlog_fatal(format, args...) (stl_modlog(STL::STL_ModLog::STL_ModLog_Fatal, format, __FILE__, __LINE__, __FUNCTION__, ##args))

#endif // _STL_LOG_H_